/* ppptiq3a.p - ITEM-SITE COST INQUIRY SUBROUTINE                           */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.             */
/* $Id:: ppptiq3a.p 4507 2011-01-25 23:18:58Z eub                          $: */
/* REVISION: 8.5            CREATED: 09/01/98   BY: *J2YN* Thomas Fernandes */
/* REVISION: 9.0      LAST MODIFIED: 01/27/99   BY: *M06M* Mugdha Tambe     */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan       */
/* REVISION: 9.0      LAST MODIFIED: 09/15/99   BY: *J3L3* Jyoti Thatte     */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 05/12/00   BY: *N09X* Antony Babu      */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KQ* myb              */
/* Revision: 1.12     BY: Zheng Huang            DATE: 02/01/02 ECO: *P000* */
/* Revision: 1.14     BY: Paul Donnelly (SB)     DATE: 06/28/03 ECO: *Q00K* */
/* Revision: 1.15     BY: Vinay Soman            DATE: 09/07/04 ECO: *P2JG* */
/* Revision: 1.16     BY: Russ Witt              DATE: 10/20/06 ECO: *R08M* */
/* $Revision: 1.18 $  BY: Zhijun Guan            DATE: 11/09/09 ECO: *R1V9* */
/*-Revision end---------------------------------------------------------------*/

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

     /* THIS SUBROUTINE DISPLAYS GL & CURRENT COST DETAILS PERTAINING TO
        THE PART/SITE COMBINATION FOR WHICH THE INQUIRY IS BEING DONE   */
   {us/bbi/mfdeclre.i}
   {us/bbi/gplabel.i}

   define variable frtitle as   character format "x(24)" no-undo.
   define variable site         like si_site             no-undo.
   define variable site1        like si_site             no-undo.
   define variable l_curr_set   like in_cur_set          no-undo.
   define variable l_gl_set     like in_gl_set           no-undo.
   define variable gl_site      like in_gl_cost_site     no-undo.
   define buffer b-in-mstr      for in_mstr.
   define variable c_fiscal_desc as character format "x(40)" no-undo.

   define new shared variable csset as character.

   define new shared frame d.
   define new shared frame d0.
   define new shared frame d1.

   define new shared workfile sptwkfl
      field element  like spt_element column-label "Element"
      field primary  like mfc_logical column-label "Pri"
      field prim2    like mfc_logical
      field ao       like spt_ao      column-label "A/O"
      field cst_tl   like spt_cst_tl  column-label "This Level"
      field cst_ll   like spt_cst_ll  column-label "Lower Level"
      field cst_tot  like spt_cst_tl  column-label "Total"
      field cat_desc as character     column-label "Category"
      field seq      like spt_pct_ll
      field part     like pt_part.

   /* PRINTABLE VERSION OF FRAME a */
   form
      pt_part        colon 14
      pt_desc1       at    36 no-label
      site           colon 14 label "Inv Site"
      pt_um          colon 30 label "UM"
      pt_desc2       at    36 no-label
   with frame a0 side-labels width 80.

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame a0:handle).

   form
      pt_part        colon 14
      pt_desc1       at    36 no-label
      site           colon 14 label "Inv Site"
      pt_um          colon 30 label "UM"
      pt_desc2       at    36 no-label
   with frame a side-labels width 80.

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame a:handle).

   form
      {us/pp/ppptmta5.i}
      pt_price          colon 14
      pt_taxable        colon 41
      pt_taxc           colon 58
      pt_fiscal_class   colon 14
      c_fiscal_desc     no-label
   with frame d1 title color normal
      (getFrameTitle("ITEM_PRICE_DATA",23))
      side-labels width 80.

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame d1:handle).

   form
      {us/pp/ppptmta9.i}
      element format "x(10)"
      cst_tl
      cst_ll format "->>>,>>>,>>9.99<<<"
      cst_tot format "->>>,>>>,>>9.99<<<"
      space(1)
      sptwkfl.primary
      cat_desc
      ao
   with frame d ? down title color normal frtitle
      width 80.

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame d:handle).

   /* FOR BOOLEAN VALUE IN DOWN FRAME,    */
   /* ENSURE TRANSLATION TO USER LANGUAGE */
   {us/gp/gpfrmdis.i &fname = "d"}

   form
      {us/pp/ppptmta9.i}
   with frame d0 1 down width 80 no-labels
      title color normal (getFrameTitle("TOTALS",16)).
   {us/wb/wbrp02.i}

   mainloop:
   repeat:

      hide frame a1.
      hide frame d0.
      hide frame d.
      hide frame d1.

      if gl_site <> site then gl_site = "".

      display
         global_part @ pt_part
         global_site @ site
      with frame a.

      if c-application-mode <> 'web' then
      prompt-for pt_part site
      with no-validate frame a
         editing:

         if frame-field = "pt_part" then do:

            /* FIND NEXT/PREVIOUS RECORD */
            {us/mf/mfnp.i pt_mstr pt_part  " pt_mstr.pt_domain = global_domain and
            pt_part "  pt_part pt_part pt_part}

         end. /* IF FRAME-FIELD = "pt_part" ... */
         else if frame-field = "site" then do:
         /*REPLACE ALT-NUM WHEN LEAVING pt_part FIELD*/
        {us/pp/ppalsu.i "input pt_part" pt_part:screen-value " pt_part:screen-value @ pt_part with frame a"}

            /* FIND NEXT/PREVIOUS RECORD */
            {us/mf/mfnp.i si_mstr site  " si_mstr.si_domain = global_domain and
            si_site "  site si_site si_site}

         end. /* IF FRAME-FIELD = "site" ... */
         else do:
            readkey.
            apply lastkey.
         end. /* ELSE ... */

         if recno <> ? then do:
            if frame-field = "pt_part" then do:

               if available pt_mstr then do:
                  display
                     pt_part
                     pt_desc1
                     pt_site @ site
                     pt_um
                     pt_desc2
                  with frame a.
               end. /* IF AVAILABLE pt_mstr ... */

            end. /* IF FRAME-FIELD = "pt_part" ... */

            if frame-field = "site" then do:

               if available si_mstr then do:
                  display si_site @ site with frame a.
               end. /* IF AVAILABLE si_mstr ... */

            end. /* IF FRAME-FIELD = "site" ... */
         end. /* IF recno <> ? ... */
      end. /* EDITING ... */
      {us/pp/ppalsu.i "input pt_part" pt_part:screen-value " pt_part:screen-value @ pt_part with frame a"}

      { us/wb/wbrp06.i &command = prompt-for
         &fields = "pt_part site"
         &frm = "a" }
      if ((c-application-mode <> 'web') or
         (c-application-mode = 'web' and
         c-web-request begins 'data')) then
      do:

         if input pt_part = "" then do:
            /* BLANK NOT ALLOWED */
            {us/bbi/pxmsg.i &MSGNUM=40 &ERRORLEVEL=3}
            if c-application-mode = 'web' then return.
            else
               undo, retry.
         end. /* if INPUT pt_part = "" ... */

         for first pt_mstr
            using  input pt_part where pt_mstr.pt_domain = global_domain  no-lock:
         end.
         if not available pt_mstr then do:
            /* ITEM NUMBER DOES NOT EXIST */
            {us/bbi/pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
            if c-application-mode = 'web' then return.
            else
               undo, retry.
         end. /* IF NOT AVAILABLE pt_mstr ... */

         if not can-find(si_mstr  where si_mstr.si_domain = global_domain and
         (si_site = input site)
            use-index si_site)
            and (input site <> "")
         then do:
            /* SITE DOES NOT EXIST */
            {us/bbi/pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}
            if c-application-mode = 'web' then return.
            else do:
               next-prompt site with frame a.
               undo, retry.
            end.
         end. /* IF NOT CAN-FIND(SI_MSTR ... */

         assign global_part = pt_part
            site
            gl_site = ""
            global_site = site.

         if site = "" then
            site1 = hi_char.
         else
         do:
            site1 = site.

            for first in_mstr
                where in_mstr.in_domain = global_domain and  in_part = pt_part
                and in_site = site no-lock:
            gl_site = in_gl_cost_site.
            end.
         end.

         display
            pt_part
            pt_desc1
            site
            pt_um
            pt_desc2
         with frame a.

         /* OUTPUT DESTINATION SELECTION */
         {us/gp/gpselout.i &printType = "terminal"
            &printWidth = 80
            &pagedFlag = " "
            &stream = " "
            &appendToFile = " "
            &streamedOutputToTerminal = " "
            &withBatchOption = "no"
            &displayStatementType = 1
            &withCancelMessage = "yes"
            &pageBottomMargin = 6
            &withEmail = "yes"
            &withWinprint = "yes"
            &defineVariables = "yes"}

         for first icc_ctrl
            where icc_ctrl.icc_domain = global_domain no-lock:
         end.

         for each in_mstr
                where in_mstr.in_domain = global_domain and  in_part = pt_part
               and in_site >= site and in_site <= site1 no-lock:

            /* CHECK FOR REPORT TERMINATION */
            {us/mf/mfrpchk.i}

            /* REPLACED INDEX SCT_SIM_PT_SITE BY SCT_SITE_PART     */

            if not can-find(first sct_det

                where sct_det.sct_domain = global_domain and (  (sct_site =
                in_site or sct_site = in_gl_cost_site)
               and   sct_part = pt_part))
               then next.

            if dev = "terminal" then
            display
               pt_part
               pt_desc1
               in_site @ site
               pt_um
               pt_desc2
            with frame a.
            else
               if dev = "window" then
            display
               pt_part
               pt_desc1
               in_site @ site
               pt_um
               pt_desc2
            with frame a0.

            pause before-hide.

            /* SEARCH THE FISCAL CLASS DESCRIPTION */
            c_fiscal_desc = "".
            {us/gp/gprunp.i "gpcodxr" "p" "getGeneralizedCodeDescription"
               "(input  ""pt_fiscal_class"",
                 input  pt_fiscal_class,
                 output c_fiscal_desc)"}

            display {us/pp/ppptmta5.i} 
               pt_price          colon 14
               pt_taxable        colon 41
               pt_taxc           colon 58
               pt_fiscal_class   colon 14
               c_fiscal_desc     no-label
            with frame d1.

            assign l_gl_set   = icc_gl_set
               l_curr_set = icc_cur_set.

            if in_gl_set <> "" then
               l_gl_set = in_gl_set.

            if in_cur_set <> "" then
               l_curr_set = in_cur_set.

            gl_site = in_gl_cost_site.

            if in_site <> in_gl_cost_site then
            for first b-in-mstr
                where b-in-mstr.in_domain = global_domain and
                b-in-mstr.in_site = in_mstr.in_gl_cost_site
               and b-in-mstr.in_part = in_mstr.in_part no-lock:
            if b-in-mstr.in_gl_set = "" then
               l_gl_set = icc_gl_set.
            else
               l_gl_set = b-in-mstr.in_gl_set.
            end.

            for first sct_det
                where sct_det.sct_domain = global_domain and  sct_sim  =
                l_gl_set
               and sct_part = pt_part
               and sct_site = gl_site no-lock:
            end.

            if available sct_det then do:
               assign csset = sct_det.sct_sim

                  frtitle =   getFrameTitle("GL_COST_DATA",18) + "(" +
                  getTermLabel("GL_COST_SOURCE_SITE",24) + ": " + gl_site +
                  " / " + getTermLabel("SET",6)  + ": " +
                  csset + ") ".

               /* DISPLAY COST DETAILS */
               {us/bbi/gprun.i ""ppptiqd.p""
                  "(input recid(sct_det), input frtitle)"}
            end. /* IF AVAILABLE sct_det ... */

            put skip.
            clear frame d all.
            hide frame d0.
            hide frame d.

            if keyfunction(lastkey) = "end-error" then
               undo, next mainloop.

            for first sct_det
                where sct_det.sct_domain = global_domain and  sct_sim  =
                l_curr_set
               and sct_part = pt_part
               and sct_site = in_site no-lock:
            end.

            if available sct_det then do:
               assign
                  csset = sct_det.sct_sim
                  frtitle = getFrameTitle("CURRENT_COST_DATA",24) + "(" +
                  getTermLabel("GL_COST_SOURCE_SITE",24) + ": " + in_site +
                  " / " + getTermLabel("SET",6)  + ": " +
                  csset + ") ".

               /* DISPLAY COST DETAILS */
               {us/bbi/gprun.i ""ppptiqd.p""
                  "(input recid(sct_det), input frtitle)"}
            end. /* IF AVAILABLE(sct_det) ... */

            clear frame d all.
            hide frame d0.
            hide frame d1.
            hide frame d.
            if keyfunction(lastkey) = "end-error" then
            undo, next
               mainloop.
            put skip.

         end. /* FOR EACH SI_MSTR */

         /* RESET PRINTER/CLOSE OUTPUT */
         {us/bbi/mfreset.i}

         /* LIST COMPLETE */
         {us/bbi/pxmsg.i &MSGNUM=8 &ERRORLEVEL=1}
      end. /* IF C-APPLICATION-MODE <> 'WEB' */

   end.
   {us/wb/wbrp04.i &frame-spec = a}
